# Sum up new wind farm capacity in each county each month during 2001-2011.
# Input: txwind_original.csv

BEGIN {
  FS = ","
  OFS = ","
}

{
  if (FNR == 1)
    next
  n = split($1,ctylist,"&")
  z = split($4,startDate,"/")
  month = startDate[1]
  year = startDate[3]

  days = $6 
  newcap = $7/n
  
  for (i = 1; i <= n; ++i) {
  county = ctylist[i]
  windcap[county,year,month] = windcap[county,year,month] + newcap
  windfarmcount[county,year,month] ++
  totalDays[county,year,month] = totalDays[county,year,month] + days 
  }
}

END {
  for (county_year_month in windcap) {
    aveDays[county_year_month] = totalDays[county_year_month]/windcap[county_year_month]
    split(county_year_month, cy, SUBSEP)
    print cy[1], cy[2], cy[3],  windcap[county_year_month], aveDays[county_year_month]
  }
}

